/*
 *Copyright (c) 2024 Black Sesame Technologies
 *
 *Licensed under the Apache License, Version 2.0 (the "License");
 *you may not use this file except in compliance with the License.
 *You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing, software
 *distributed under the License is distributed on an "AS IS" BASIS,
 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *See the License for the specific language governing permissions and
 *limitations under the License.
*/

#ifndef HSCG_FIFOINTERFACE_H
#define HSCG_FIFOINTERFACE_H

#ifdef __cplusplus
extern "C" {
#endif


/*==================================================================================================
 *                                        INCLUDE FILES
 * 1) system and project includes
 * 2) needed interfaces from external units
 * 3) internal and external interfaces from this unit
 ==================================================================================================*/
#include "StandardTypes.h"
#include "Hscg_InterfaceConfig.h"
/*==================================================================================================
 *                              SOURCE FILE VERSION INFORMATION
 ==================================================================================================*/

/*==================================================================================================
 *                                     FILE VERSION CHECKS
 ==================================================================================================*/

/*==================================================================================================
 *                                          CONSTANTS
 ==================================================================================================*/

extern const uint32 Hscg_Can_u32BlrinBaseAddress[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
extern const uint32 Hscg_Can_u32BlroutBaseAddress[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
extern const uint32 Hscg_Can_u32TxackBaseAddress[HSCG_CAN_CONFIG_MAXCTRL_COUNT +
                                                 HSCG_CAN_MAX_POLLING_CLASSES];
extern const uint32 Hscg_Can_u32RxoutBaseAddress[HSCG_CAN_CONFIG_MAXCTRL_COUNT +
                                                 HSCG_CAN_MAX_POLLING_CLASSES];

extern const uint32 Hscg_Can_u32NotifFifo0BaseAddress[HSCG_CAN_CONFIG_HIF_COUNT];
extern const uint32 Hscg_Can_u32NotifFifo1BaseAddress[HSCG_CAN_CONFIG_HIF_COUNT];

extern const uint32 Hscg_Can_u32RxinBaseAddress[HSCG_CAN_CONFIG_HIF_COUNT];
extern const uint32 Hscg_Can_u32CmdBaseAddress[HSCG_CAN_CONFIG_HIF_COUNT];

extern const uint32 Hscg_Can_u32RxinLogBaseAddress[1];
extern const uint32 Hscg_Can_u32RxoutLogBaseAddress[1];
/*==================================================================================================
 *                                      DEFINES AND MACROS
 ==================================================================================================*/
#define HSCG_CONFIG_FIFO_DEPTH_U8 ((uint8)16U)

/** @brief Configuration value of register FMR of the FIFO. */
#define HSCG_FIFO_CONFIG_FMR_U32 ((uint32)0x00000420)

#define HSCG_FIFO_FFULLD_U32 ((uint32)0x00000001U)
#define HSCG_FIFO_FEMTYD_U32 ((uint32)0x00000002U)
#define HSCG_FIFO_SR_QCOUNT_SHIFT_U8 ((uint8)24U)

#define HSCG_FIFO_FCR_FIFOEN_U32 ((uint32)0x00000001U)
#define HSCG_FIFO_FCR_FLENOWEN_U32 ((uint32)0x00000002U)
#define HSCG_FIFO_FCR_POPEN_U32 ((uint32)0x00000004U)
#define HSCG_FIFO_FCR_PUSHEN_U32 ((uint32)0x00000008U)
#define HSCG_FIFO_FCR_FLUSH_U32 ((uint32)0x00000010U)

#define HSCG_FIFO_FCR_RESET_U32 ((uint32)0x0U)

/*Generic defines used to access STATUS, ILR and IER registers of FIFOs.*/
#define HSCG_FIFO_FFULL_U32 ((uint32)0x00000100U)
#define HSCG_FIFO_FNFULL_U32 ((uint32)0x00000200U)
#define HSCG_FIFO_FEMTY_U32 ((uint32)0x00000400U)
#define HSCG_FIFO_FNEMTY_U32 ((uint32)0x00000800U)
#define HSCG_FIFO_POPEVT_U32 ((uint32)0x00001000U)
#define HSCG_FIFO_WMKFL_U32 ((uint32)0x00002000U)
#define HSCG_FIFO_WMKEM_U32 ((uint32)0x00004000U)

/* Default value returned when popping an empty fifo */
#define HSCG_FIFO_NULL_VALUE ((uint32)0xFFFFFFFFU)

/* Specific FIFOs base address calculation macros. */
#define HSCG_GET_BLRIN_BASE_ADDRESS(u8HwCtrl)                                  \
    ((uint32)(HSCG_BLRIN0_BASEADDR + ((uint32)(u8HwCtrl) * (uint32)0x400U)))
#define HSCG_GET_BLROUT_BASE_ADDRESS(u8HwCtrl)                                 \
    ((uint32)(HSCG_BLROUT0_BASEADDR + ((uint32)(u8HwCtrl) * (uint32)0x400U)))
#define HSCG_GET_TXACK_BASE_ADDRESS(u8HwCtrl)                                  \
    ((uint32)(HSCG_TXACK0_BASEADDR + ((uint32)(u8HwCtrl) * (uint32)0x400U)))
#define HSCG_GET_RXIN_BASE_ADDRESS(u8HwCtrl)                                   \
    ((uint32)(HSCG_RXIN0_BASEADDR + ((uint32)(u8HwCtrl) * (uint32)0x400U)))
#define HSCG_GET_RXOUT_BASE_ADDRESS(u8HwCtrl)                                  \
    ((uint32)(HSCG_RXOUT0_BASEADDR + ((uint32)(u8HwCtrl) * (uint32)0x400U)))
#define HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo)                           \
    ((uint32)(HSCG_GENERIC_FIFO_BASEADDR +                                     \
              ((uint32)(u8GenFfo) * (uint32)0x400U)))

#define HSCG_GENERIC_FIFO_CONFIG(u8GenFfo)                                     \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo)))
#define HSCG_GENERIC_FIFO_STATUS0(u8GenFfo)                                    \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo) + 0x04U))
#define HSCG_GENERIC_FIFO_STATUS1(u8GenFfo)                                    \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo) + 0x08U))
#define HSCG_GENERIC_FIFO_IER(u8GenFfo)                                        \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo) + 0x0CU))
#define HSCG_GENERIC_FIFO_ILR(u8GenFfo)                                        \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo) + 0x10U))
#define HSCG_GENERIC_FIFO_PUSH0(u8GenFfo)                                      \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo) + 0x14U))
#define HSCG_GENERIC_FIFO_POP0(u8GenFfo)                                       \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo) + 0x24U))
#define HSCG_GENERIC_FIFO_FMR(u8GenFfo)                                        \
    ((uint32)(HSCG_GET_GENERIC_FIFO_BASE_ADDRESS(u8GenFfo) + 0x34U))

#define HSCG_FIFO_STATUS0(u32BaseAddr) ((uint32)(u32BaseAddr + 0x04U))
#define HSCG_FIFO_STATUS1(u32BaseAddr) ((uint32)(u32BaseAddr + 0x08U))
#define HSCG_FIFO_IER(u32BaseAddr) ((uint32)(u32BaseAddr + 0x0CU))
#define HSCG_FIFO_PUSH0(u32BaseAddr) ((uint32)(u32BaseAddr + 0x14U))
#define HSCG_FIFO_POP0(u32BaseAddr) ((uint32)(u32BaseAddr + 0x24U))

#define HSCG_FIFO_BLRIN_BASE_ADDRESS(u8HwCtrl)                                 \
    (Hscg_Can_u32BlrinBaseAddress[u8HwCtrl])
#define HSCG_FIFO_RXOUT_BASE_ADDRESS(u8HwCtrl)                                 \
    (Hscg_Can_u32RxoutBaseAddress[u8HwCtrl])
#define HSCG_FIFO_TXACK_BASE_ADDRESS(u8HwCtrl)                                 \
    (Hscg_Can_u32TxackBaseAddress[u8HwCtrl])
#define HSCG_FIFO_BLROUT_BASE_ADDRESS(u8HwCtrl)                                \
    (Hscg_Can_u32BlroutBaseAddress[u8HwCtrl])

#define HSCG_NOTIF_FIFO0_BASE_ADDRESS(u8HostCore)                              \
    (Hscg_Can_u32NotifFifo0BaseAddress[u8HostCore])
#define HSCG_NOTIF_FIFO1_BASE_ADDRESS(u8HostCore)                              \
    (Hscg_Can_u32NotifFifo1BaseAddress[u8HostCore])

#define HSCG_FIFO_RXIN_BASE_ADDRESS(u8HostCore)                                \
    (Hscg_Can_u32RxinBaseAddress[u8HostCore])
#define HSCG_FIFO_CMD_BASE_ADDRESS(u8HostCore)                                 \
    (Hscg_Can_u32CmdBaseAddress[u8HostCore])



/*==================================================================================================
 *                                      Interrupts
 ==================================================================================================*/

/*==================================================================================================
 *                                             ENUMS
 ==================================================================================================*/

/*==================================================================================================
 *                                STRUCTURES AND OTHER TYPEDEFS
 ==================================================================================================*/

/*==================================================================================================
 *                                GLOBAL VARIABLE DECLARATIONS
 ==================================================================================================*/

/*==================================================================================================
 *                                    FUNCTION PROTOTYPES
 ==================================================================================================*/

#ifdef __cplusplus
}
#endif

#endif /* HSCG_FIFOINTERFACE_H */

/** @} */
